<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>系统维护</title>
    <!-- Bootstrap -->
    <link href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>

    <link rel="shortcut icon" type="imagges/x-ion" href="resources/img/.png"/>
    <!--                                              网页小图标  -->
    <link rel="stylesheet" type="text/css" href="resources/css/table.css" />
</head>
<body>

<div></div>

<div id="dv">

    <h3 style="font-size: 18px;">&nbsp;系统维护&nbsp;&nbsp;>&nbsp;权限管理&nbsp;</h3>

    <div>
        <div style="display: inline-block;margin-top: 12px;">
            <form id="search-form" action="/Supermarket1_war/permissionsServlet?method=PermissionSearch" method="post">
                <input type="text" name="uname" value="Search" id="insearch"  onfocus="if (value=='Search'){value=''}" onblur="if (value == ''){value='Search'} " />
                <input type="hidden" value="PermissionSearch" name="method" />
                <button  type="submit" style="background-color: #FFFFFF;width: 35px;height: 35px;border-radius: 5px;border-style: none; background-size: 37px;vertical-align: middle;outline: none;">
                    <img type="submit"  src="resources/img/seach.png" style="height: 30px;width: 30px;vertical-align: middle;"/>
                </button>
            </form>
        </div>
    </div>

    <div class="fixedTable">
        <table cellspacing="0" class="myTable" id="nav_tab" align="center">
            <thead style="text-align: center">
            <tr id="tr3" bgcolor="#1976d5" >
                <th>员工ID</th>
                <th>员工名称</th>
                <th>员工职务</th>

                <th>操作</th>
            </thead>
            <tbody class="grid" align="center">
            <c:forEach items="${list}" var="item" varStatus="status">
                <tr height="40px" width="100px">
                    <td>${item.uid }</td>
                    <td>${item.uname }</td>
                    <td>

                        <c:choose>
                            <c:when test = "${item.rights==1}">管理者</c:when>
                            <c:when test = "${item.rights==2}">经理</c:when>
                            <c:when test = "${item.rights==3}">员工</c:when>
                        </c:choose>
                    </td>
                    <td>
                        <button class="btn btn-primary btn-sm saveModal" id="${item.uid }">编辑权限</button>
                    </td>

                </tr>
            </c:forEach>

            </tr>


            </tbody>
        </table>
    </div>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">

                <!-- 内容 -->
                <div class="modal-body" style="padding:15px 15px 0px 50px">
                    <!-- 表单 -->
                    <form id="adduser" class="form-horizontal" role="form">
                        <div class="form-group">
                            <label  class="col-sm-2 control-label">修改权限</label>
                            <div class="col-sm-10">
                                <div class="radio">
                                    <label>
                                        <input type="radio" name="rights" value="1" checked/>管理者
                                    </label>&nbsp;
                                    <label class="margin-left-2em">
                                        <input type="radio" name="rights"  value="2"/>经理
                                    </label>&nbsp;
                                    <label class="margin-left-2em">
                                        <input type="radio" name="rights"  value="3"/>员工
                                    </label>
                                </div>
                            </div>
                        </div>

                        <!-- 创建时间后台直接获取  -->

                        <!-- 隐藏表单，接收ID -->
                        <div class="form-group">
                            <div class="col-sm-10">
                                <input type="hidden" class="form-control" id="uid" name="uid" >
                            </div>
                        </div>

                    </form>
                </div>


                <div class="modal-footer" style="padding:10px 15px 10px 5px">
                    <button type="button" class="btn btn-primary saveBtn">确定</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>





</div>



</body>
</html>
<script>
    $('.saveModal').click(function(){
        var str = $(this).text();//新增或编辑
        var id = $(this).attr('id');
        var modalObj = $('#myModal');//弹出框对象
        modalObj.find('#myModalLabel').text(str);//moda 头部
        $('#upid').removeAttr("disabled");//menu 特殊处理 可选择父级
        $('.buttonsDiv').remove();//menu 特殊处理 移除buttons
        $("#ausername,#apassword").removeAttr('disabled');//user 特殊处理
        if( str == "编辑权限" )
        {
            //编辑时Ajax后台请求数据，这里前端直接写死
            $.ajax({
                url:'/Supermarket1_war/permissionsServlet?method=PermissionUpdateFind',
                cache:false,
                type:'get',
                dataType:'json',

                //async:false,//同步
                data:{ uid : id},
                success:function(data){

                    renderDataToHtml( data );//  渲染数据
                    $('#myModal').modal('show');

                },

            });

        }

    });

    /*
     *@todo 点击保存按钮,添加，编辑确认按钮
    /**

     /*
	 *@todo 点击保存按钮,添加，编辑确认按钮
	 */
    $('.saveBtn').click(function(){
        var modalObj = $(this).parents('#myModal');//弹出框对象
        var str = modalObj.find( '#myModalLabel' ).text();//moda 头部
        var data = modalObj.find('form').serialize();
        $.ajax({
            url:'/Supermarket1_war/permissionsServlet?method=PermissionUpdate',
            data:data,
            cache:false,
            dataType:'json',
            type:'post',
            success:function(result){
                if( result == 0 )
                    alert("修改失败")
                if(result==1){
                    $('#myModal').modal('hide');//隐藏
                    window.location.href="permissionsServlet?method=PermissionFind"
                }


            }
        });

    });


    //如果是编辑操作，数据回显操作
    function renderDataToHtml(data){
        $("#uid").val(data['uid']);	//给隐藏表单主键ID赋值
        $('input[type="radio"][name="rights"][value="'+ data['rights'] +'"]').prop("checked",'checked');

    }
</script>
